package practice;

import practice.domain.Person;

import java.lang.reflect.Field;

public class 通过反射操作属性 {
    public static void main(String[] args) throws Exception {
        Class clazz = Person.class;

        Person person = new Person();
        Field field = clazz.getDeclaredField("name");
        field.setAccessible(true);
        field.set(person,"shibixiu");
        System.out.println(field.get(person));
        System.out.println(person);

        Field field1 = clazz.getDeclaredField("age");
        field1.setAccessible(true);
        field1.set(person,23);
        System.out.println(field1.get(person));
        System.out.println(person);

    }
}
